define(["utils"],function(utils){

    var Component = function(config){
        var _this = this;
        this.itemData = config.itemData;
        this.status = "unChecked"; //unChecked indeterminate
        this.valueData = this.itemData.value;
        this.group = config.group;
        this.selector = config.selector;
        this.deptId = this.itemData.value.deptId.toString();
        var children =  this.selector.DeptDictData[this.deptId]||[];

        this.$el = $("<div class='person-selector-item'></div>");
        var className = children.length>0?'person-selector-triangle person-selector-triangle-dept':'person-selector-triangle';
        this.triangle = $("<span class='"+className+"'></span>");
        this.checkbox = $("<span class='person-selector-checkbox dc-depart-checkbox yy-fontawesome'></span>");
      	this.text = $("<span class='person-selector-text'>"+this.valueData.deptName+"</span>");
        this.$el.append(this.triangle).append(this.checkbox).append(this.text);

        this.triangle.bind("click",function(e){
          e.stopPropagation();
          e.preventDefault();
          _this.openIfNeed();
        });

        this.$el.bind("click",function(e){
          e.stopPropagation();
          e.preventDefault();
          _this.group.groupHeaderItemCheckChange();
          _this.selector.selectedChange(_this);
        });
    }

    Component.prototype={
      parentCheckedIfNeed:function(){

      },
      setCheck:function(status){
        //不做其它逻辑
        this.status = status;
        if(status==="checked"){
          this.checkbox.addClass("checked").removeClass("mid");
        }else if(status === "unChecked"){
          this.checkbox.removeClass("checked").removeClass("mid");
        }else if(status === "indeterminate"){
          this.checkbox.removeClass("checked").addClass("mid");
        }else {
          console.error("setCheck 参数错误");
        }
      },

      _loadPersonData:function(){
        var _this = this;
        _this.group.open();
      },
      openIfNeed:function(){
        this.group.toggle();
      }
    }


    return Component;
});
